import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { GButton } from "../../../../com/mui/controls/GButton";
import { EventName } from "../../mvc/EventName";
type int = number;
//class NumberTool
    
    export  class NumberTool /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        public set maxNumber(arg1: int)
        {
            this._maxNumber = arg1;
            return;
        }

        public get number(): int
        {
            return this._number;
        }

        public set currentNumber(arg1: int)
        {
            this._number = arg1;
            this._numberTxt.text = this._number.toString();
            return;
        }

        /* internal  */init(): void
        {
            this._numberTxt = new GTextInput();
            this._numberTxt.x = 0;
            this._numberTxt.y = 0;
            this._numberTxt.width = 25;
            this._numberTxt.height = 18;
            this._numberTxt.restrict = "0-9";
            this._numberTxt.text = "1";
            this._numberTxt.styleName = "GTextInput";
            this._numberTxt.drawNow();
            this._numberTxt.addEventListener(flash.events.Event.CHANGE, this.onNumberTxtChangeHandler);
            addChild(this._numberTxt);
            return;
        }

        public setButton(): void
        {
            this._addBtn = new GButton();
            this._addBtn.x = 25;
            this._addBtn.y = 0;
            this._addBtn.width = 18;
            this._addBtn.height = 18;
            this._addBtn.label = "";
            this._addBtn.styleName = "AddBtn";
            this._addBtn.drawNow();
            this._addBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onAddBtnClickHandler);
            this._addBtn.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onAddBtnMouseDownHandler);
            this._addBtn.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onAddBtnMouseUpHandler);
            addChild(this._addBtn);
            return;
        }

        /* internal  */onNumberTxtChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this._number = parseInt(this._numberTxt.text);
            if (this._number > this._maxNumber) 
            {
                this._number = this._maxNumber;
                this._numberTxt.text = this._number.toString();
            }
            if (this._numberTxt.text == "") 
            {
                this._number = 1;
                this._numberTxt.text = "1";
            }
            arg1.stopImmediatePropagation();
            dispatchEvent(new Object /* flash.events.Event */(EventName.NumberToolAmountChange));
            return;
        }

        /* internal  */onAddBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._number < this._maxNumber) 
            {
                var loc1;
                var loc2=((loc1 = this)._number + 1);
                loc1._number = loc2;
                this._numberTxt.text = this._number.toString();
                dispatchEvent(new Object /* flash.events.Event */(EventName.NumberToolAmountChange));
            }
            return;
        }

        /* internal  */onAddBtnMouseDownHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            addEventListener(flash.events.Event.ENTER_FRAME, this.onEnterframeHandler);
            return;
        }

        /* internal  */onAddBtnMouseUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._count = 0;
            removeEventListener(flash.events.Event.ENTER_FRAME, this.onEnterframeHandler);
            return;
        }

        /* internal  */onEnterframeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1;
            var loc2=((loc1 = this)._count + 1);
            loc1._count = loc2;
            if (this._count % 6 == 0) 
            {
                if (this._number < this._maxNumber) 
                {
                    loc2 = ((loc1 = this)._number + 1);
                    loc1._number = loc2;
                    this._numberTxt.text = this._number.toString();
                    dispatchEvent(new Object /* flash.events.Event */(EventName.NumberToolAmountChange));
                }
                else 
                {
                    this._count = 0;
                    removeEventListener(flash.events.Event.ENTER_FRAME, this.onEnterframeHandler);
                }
            }
            return;
        }

        /* internal */ /* var */_numberTxt: GTextInput;

        /* internal */ /* var */_addBtn: GButton;

        /* internal */ /* var */_number: int=1;

        /* internal */ /* var */_maxNumber: int;

        /* internal */ /* var */_count: int=0;
    }
